/*
 * Created on 2008-1-15
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.tongji.quickCRUDQ.dao.jdbc;

import java.util.List;

import com.tongji.quickCRUDQ.dao.RoleDao;
import com.tongji.quickCRUDQ.model.CommonBean;

/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class RoleDaoJdbc extends BaseDaoJdbc implements RoleDao {
   private String tableName="ROLE";
   private String beanName="role";
   
   public CommonBean createRole(){
   	return this.createBean(tableName,beanName);
   }
   
   public CommonBean findUserRoles(String userId){
   	  CommonBean roleBean=this.createRole();
   	  String sql="select * from role where id in(select role_id from user_role where user_id=?)";
   	  List roles=this.getCommonDao().select(sql,new String[]{userId});
   	  roleBean.addData(roles);
   	  return roleBean;
   }
   
   public CommonBean findOtherRoles(String userId){
 	  CommonBean roleBean=this.createRole();
   	  String sql="select * from role where id not in(select role_id from user_role where user_id=?)";
   	  List roles=this.getCommonDao().select(sql,new String[]{userId});
   	  roleBean.addData(roles);
   	  return roleBean;
   }
   
   public CommonBean findAllRoles(){
   	  CommonBean roleBean=this.createRole();
   	  String sql="select * from role ";
   	  List roles=this.getCommonDao().select(sql);
   	  roleBean.addData(roles);
   	  return roleBean;
   }
   
   

}
